<?php

require_once("utils/template.php");
require_once("utils/db.php");

//////////////////////////////////////
// Business/Data Layer
//////////////////////////////////////

$sql = "select f_titre, f_annee, f_nb_exemplaires, 
	array_to_string(ARRAY(
		select g_nom from film_genre fg, genres g
		where f.f_id = fg.f_id
		and fg.g_id = g.g_id), ', ') as genres,
	array_to_string(ARRAY(
		select r_nom from film_real fr, realisateurs r
		where f.f_id = fr.f_id
		and fr.r_id = r.r_id), ', ') as realisateurs
from films f";

$rq = execQuery($sql);
$res = $rq->fetchAll();


//////////////////////////////////////////
// View Layer
//////////////////////////////////////////
$main = new Template('views/catalogue_films.view.php', array(
    'title' => 'Catalogue films',
    'res' => $res,
));
$main->render();

?>
